﻿using System;
using System.Web.UI;
using SBACN.WebSite.Cache;
using SBACN.WebSite.Code;

namespace SBACN.WebSite.UC
{
	public partial class Navigator : BaseControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if(!Page.IsPostBack)
			{
				InitCtrl();
			}
		}

		private void InitCtrl()
		{
			int navLevel = 1;
			while (SystemCode.Length > navLevel * 4)
			{
				var navItem = SystemMapCache.Instance[SystemCode.Substring(0, navLevel * 4)];
				if(navItem != null)
				{
					this.nav.InnerHtml += "<a href=\"" + (string.IsNullOrWhiteSpace(navItem.CURL) ? "#" : BasePage.UrlAppendQueryString(navItem.CURL, "st", navItem.Code, false)) + "\">" + navItem.CText + "</a> > ";
				}
				navLevel++;
			}
			var curItem = SystemMapCache.Instance[SystemCode];
			if(curItem != null)
				this.nav.InnerHtml += curItem.CText;
		}
	}
}